package com.dreamana.components
{
	import com.dreamana.ui.BaseComponent;
	import com.dreamana.ui.ISkinnable;
	import com.dreamana.ui.SkinGraphics;
	
	import flash.display.BitmapData;
	import flash.display.Graphics;
	import flash.display.Shape;
	import flash.events.Event;
	import flash.geom.Rectangle;
	
	public class Panel extends BaseComponent implements ISkinnable
	{
		protected var _back:Shape;
		protected var _backColor:int = -1;
		protected var _backTexture:BitmapData;
		protected var _backScale9Grid:Rectangle;
		
		public function Panel(w:int, h:int)
		{
			_width = w;
			_height = h;
			
			this.init();
		}
		
		override protected function addChildren():void
		{
			//do nothing
		}
		
		//--- PUBLIC METHODS ---
		
		override public function draw():void
		{
			var g:Graphics = this.graphics;
			
			g.clear();
			
			if(_backTexture) {
				if(_backScale9Grid) SkinGraphics.fill9Grid(g, _backTexture, _width, _height, _backScale9Grid, false);
				else SkinGraphics.fillRect(g, _backTexture, _width, _height);
			}
			else if(_backColor >= 0) {
				SkinGraphics.drawBlank(g, _width, _height, _backColor);
			}
			else {
				SkinGraphics.drawWireFrame(g, _width, _height);
			}
		}
		
		override public function setStyle(style:String, value:Object):void
		{
			super.setStyle(style, value);
			
			switch(style) {
				case "background-color":
					_backColor = value as Number;
					invalidate();
					break;
				case "background-image":
					_backTexture = value as BitmapData;
					invalidate();
					break;
				case "background-9grid":
					_backScale9Grid = value as Rectangle;
					invalidate();
					break;
			}
		}
				
		//--- EVENT HANDLERS ---
				
		//--- GETTER/SETTERS ---
		public function get background():Shape { return _back; }
	}
}